package cn.sort;


import java.util.Date;

public class HanoiTower {

    public static void moveLeftToRight(int n) {
        if (n == 1) {
            System.out.println("move 1 from left to right");
            return;
        }
        moveLeftToMid(n - 1);
        System.out.println("move " + n + " from left to right");
        moveMidToRight(n - 1);
    }

    public static void moveLeftToMid(int n) {
        if (n == 1) {
            System.out.println("move 1 from left to mid");
            return;
        }
        moveLeftToRight(n-1);
        System.out.println("move " + n + " from left to mid");
        moveRightToMid(n-1);
    }
    public static void moveRightToMid(int n){
        if (n == 1){
            System.out.println("move 1 from right to mid");
            return;
        }
        moveRightToLeft(n-1);
        System.out.println("move "+n+" from right to mid");
        moveRightToMid(n-1);
    }

    public static void moveRightToLeft(int n){
        if (n == 1) {
            System.out.println("move 1 from right to left");
            return;
        }
        moveRightToMid(n-1);
        System.out.println("move "+ n + " from right to left");
        moveMidToLeft(n-1);
    }

    public static void moveMidToLeft(int n){
        if (n == 1){
            System.out.println("move 1 from mid to left");
            return;
        }
        moveMidToRight(n-1);
        System.out.println("move " + n + " from mid to left");
        moveRightToLeft(n-1);
    }

    public static void moveMidToRight(int n) {
        if (n==1){
            System.out.println("move 1 from mid to right");
            return;
        }
        moveMidToLeft(n-1);
        System.out.println("move " + n + " from mid to right");
        moveLeftToRight(n-1);
    }

    public static void main(String[] args) {
        long begin = new Date().getTime();
        moveLeftToRight(20);
       long end = new Date().getTime();
        System.out.println(end - begin);


    }
}
